<?
/*--|   CACHE
  Software: Socially
   Version: 1.0
   Contact: http://socially.googlecode.com
      Info: http://socially.googlecode.com
   Support: http://socially.googlecode.com
-------------------------------------------------------------------------- 
    Author: goker cebeci | http://gokercebeci.com
-------------------------------------------------------------------------- 
   License: Distributed under the GNU General Public License (GPL)
            http://www.gnu.org/licenses/gpl.html
 This program is distributed in the hope that it will be useful - WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.
-------------------------------------------------------------------------*/
$memcache_connection;
class cache {
    public static function connect(){
        //global $memcache_connection;
        //$memcache_connection = @memcache_pconnect(MEMCACHEHOST, MEMCACHEPORT);
        //if(DEBUG)
            //$memcache_connection->memcache_debug(true);
    }
    public static function get($a){
        apc_fetch('foo');
        /*global $memcache_connection,$debug;*/
        global $debug;
        $q = null;
        if(is_array($a)) foreach($a as $i) {
            //$r[$i] = $memcache_connection->get(CACHEPREFIX.'_'.$i);
            $r[$i] = apc_fetch(CACHEPREFIX.'_'.$i);
            $q .= $i.', ';
        }
        //else $r = $memcache_connection->get(CACHEPREFIX.'_'.$a);
        else $r = apc_fetch(CACHEPREFIX.'_'.$a);
        $caller = debug_backtrace();
        if(ACCESS >= DEBUG) {
            $debug[] = array('query' => 'cache::'.($q?$q:$a), 'file' => $caller[0]['file'],'line' => $caller[0]['line'],'error'=>$r?false:true);
        }
        return $r;
    }
    public static function set($key, $var, $compress = false, $ttl = 0){
        apc_store(CACHEPREFIX.'_'.$key, $var, $ttl);
        //global $memcache_connection;
        //$memcache_connection->set(CACHEPREFIX.'_'.$key, $value, $compress, $time);
    }
    public static function del($a){
        if(is_array($a)) foreach($a as $i) apc_delete(CACHEPREFIX.'_'.$i);
        else apc_delete(CACHEPREFIX.'_'.$a);
        /*global $memcache_connection;
        $slabs = $memcache_connection->getExtendedStats('slabs');
        $items = $memcache_connection->getExtendedStats('items');
        foreach($slabs as $server => $slab) {
            if($slab)
            foreach($slab AS $slabID => $slabMeta) {
                $dump = $memcache_connection->getExtendedStats('cachedump',(Int)$slabID);
                foreach($dump AS $server => $entries) {
                    if($entries) foreach($entries AS $key => $data) {
                        if(is_array($a)) foreach($a as $i) {
                            if(strchr($key, CACHEPREFIX.'_'.$i))
                            $memcache_connection->delete($key);
                        } elseif(strchr($key, CACHEPREFIX.'_'.$a))
                            $memcache_connection->delete($key);
                    }
                }
            }
        }
        //if(is_array($a)) foreach($a as $i) $memcache_connection->delete(CACHEPREFIX.'_'.$i);
        //else $memcache_connection->delete(CACHEPREFIX.'_'.$a);*/
    }
    public static function disconnect(){
        //global $memcache_connection;
        //if($memcache_connection) $memcache_connection->close();
    }
    public static function keys($a){
        /*global $memcache_connection;
        $slabs = $memcache_connection->getExtendedStats('slabs');
        $items = $memcache_connection->getExtendedStats('items');
        foreach($slabs as $server => $slab) {
            foreach($slab AS $slabID => $slabMeta) {
                $dump = $memcache_connection->getExtendedStats('cachedump',(Int)$slabID);
                foreach($dump AS $server => $entries) {
                    if($entries) foreach($entries AS $key => $data) {
                        if(strchr($key, CACHEPREFIX.'_'.$a))
                                $list[] = $key;
                                /*$list[$key] = array(
                                     'key' => $key,
                                     'server' => $server,
                                     'slabId' => $slabId,
                                     'detail' => $data,
                                     'age' => $items[$server]['items'][$slabID]['age'],
                                     );*//*
                        }
                }
            }
        }
        //ksort($list);
        return $list;*/
    }
}
?>
